package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.RbacManagerDao;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class RbacManagerServiceImpl implements RbacManagerService {
    @Autowired(required = false)
    RbacManagerDao rbacManagerDao;

    @Override
    public ResponseEntity findAll(int currentPage, int pageSize, RbacManager rbacManager) {
        //分页
        PageHelper.startPage(currentPage, pageSize);
        List<RbacManager> rbacManagerList=rbacManagerDao.findAll(rbacManager);
        PageInfo<RbacManager> of = PageInfo.of(rbacManagerList);
        ResponseEntity<List> responseStatus=new ResponseEntity<>();
        if(rbacManagerList.size()>0){
            responseStatus.setCode(200);
            responseStatus.setData(rbacManagerList);
            responseStatus.setMsg("查询成功");
        }else{
            responseStatus.setCode(500);
            responseStatus.setData(null);
            responseStatus.setMsg("查询失败");
        }
        return responseStatus;
    }

    @Override
    public ResponseEntity deleteOne(int id) {
        int num =rbacManagerDao.deleteOne(id);
        if(num>0) {
            return new ResponseEntity(200,"删除成功",null);
        }else {
            return new ResponseEntity(500,"删除失败",null);
        }
    }

    @Override
    public ResponseEntity addONE(RbacManager rbacManager) {
        int num =rbacManagerDao.addOne(rbacManager);
        if(num>0) {
            return new ResponseEntity(200,"添加成功",null);
        }else {
            return new ResponseEntity(500,"添加失败",null);
        }
    }

    @Override
    public ResponseEntity updateOne(int id) {
        int num = rbacManagerDao.updateOne(id);
        if(num>0) {
            return new ResponseEntity(200,"添加成功",null);
        }else {
            return new ResponseEntity(500,"添加失败",null);
        }
    }
}
